package com.zl.controller;

import com.zl.domain.Order;
import org.springframework.web.bind.annotation.*;

/**
 * @author zl
 * @date 2023/3/19
 * @apiNote
 */
@RestController
public class ParamController {

    @GetMapping("/testUrl/{name}/{age}")
    public String testUrl(@PathVariable("name") String name,@PathVariable("age") Integer age){
        System.out.println(name + ":" + age);
        return "ok";
    }

    /**
     * required = false 表示可以传一个空的,  为true时即为不能传空
     * @param name
     * @return
     */
    @GetMapping("/oneParam")
    public String oneParam(@RequestParam(required = false) String name){
        System.out.println(name);
        return "ok";
    }

    @GetMapping("/twoParam")
    public String twoParam(@RequestParam(required = false) String name,@RequestParam(required = false) Integer age){
        System.out.println(name + ":" + age);
        return "ok";
    }

    @PostMapping("/oneObject")
    public String oneObject(@RequestBody Order order){
        System.out.println(order);
        return "ok";
    }

    @PostMapping("/oneObjectParam")
    public String oneObjectParam(@RequestBody Order order,@RequestParam(required = false) String name){
        System.out.println(order);
        System.out.println(name);
        return "ok";
    }
}
